import 'package:flutter/material.dart';

class ClothBox extends StatelessWidget {
  final Widget childWidget;
  final Map<String, dynamic> cloth;
  final bool hasImage;

  ClothBox(
      {required this.childWidget, required this.cloth, required this.hasImage});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        showDialog(
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(20),
                side: BorderSide(color: Colors.indigo, width: 3),
              ),
              backgroundColor: Colors.white,
              title: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '详细信息',
                    style: TextStyle(
                      color: Colors.black,
                      fontSize: 18.0,
                    ),
                  ),
                  TextButton(
                    child: Icon(
                      Icons.cancel_outlined,
                      color: Colors.black54,
                      size: 40,
                    ),
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                  ),
                ],
              ),
              content: Container(
                height: MediaQuery.of(context).size.height - 600,
                width: MediaQuery.of(context).size.width - 80,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Expanded(
                        child: GestureDetector(
                      child: childWidget,
                      onTap: () {
                        if (hasImage) {
                          showDialog(
                            context: context,
                            builder: (BuildContext context) {
                              return AlertDialog(
                                contentPadding: EdgeInsets.zero,
                                content: childWidget,
                              );
                            },
                          );
                        }
                      },
                    )),
                    SizedBox(
                      height: 10,
                    ),
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          'ID：' + cloth['userClothId'].toString(),
                          style: TextStyle(fontSize: 16),
                        ),
                        Text(
                          '名称：' + cloth['name'],
                          style: TextStyle(fontSize: 16),
                        ),
                        Text(
                          '大类：' + cloth['category'],
                          style: TextStyle(fontSize: 16),
                        ),
                        Text(
                          '小类：' + cloth['subcategory'],
                          style: TextStyle(fontSize: 16),
                        ),
                      ],
                    )
                  ],
                ),
              ),
            );
          },
        );
      },
      child: Container(
        width: 100,
        height: 160,
        margin: EdgeInsets.only(bottom: 25, right: 10,top: 10),
        decoration: BoxDecoration(
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.2), // 阴影颜色和透明度
              spreadRadius: 2, // 阴影扩展半径
              blurRadius: 5, // 阴影模糊半径
              offset: Offset(0, 5), // 阴影偏移量
            ),
          ],
          color: Colors.white,
          borderRadius: BorderRadius.only(
              topRight: Radius.circular(25), topLeft: Radius.circular(25)),
        ),
        child: hasImage
            ? Column(
                children: [
                  Expanded(
                      child:
                          Center(child:Text('编号:'+cloth['userClothId'].toString()),)),
                  childWidget,
                ],
              )
            : Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text('编号:'+cloth['userClothId'].toString()),
                  childWidget,
                ],
              ),
      ),
    );
  }
}
